

var main = {
    swiper: function() {
        var mySwiper = new Swiper('.swiper-container',{
            autoplay : 3000,//可选选项，自动滑动
            loop : true//可选选项，开启循环
        })
        $('.ext-prev').on('click', function() {
            mySwiper.swipePrev();
        })
        $('.ext-next').on('click', function() {
            mySwiper.swipeNext();
        })
    },
    getRecomData1: function() {
        $.ajax({
            url: window.domain + window.requestUrl.getIndexRecomUrl,
            type: 'get',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            data: {
                platId: 4,
                pageSize: 4
            },
            success: function(res) {
                if(typeof(res.not_login) != 'undefined') {
                    window.setCookie('go_back_link', window.location.href);
                    window.location.href = './login.html';
                    return;
                }
                if(res.status) {
                    var list = res.data.result.list;
                    var tpl = '';
                    $.each(list, function(index, item) {
                        tpl += '<li>\
                                    <a href="./weixin-detail.html?id='+item.id+'" target="_blank">\
                                        <img src="'+item.iconUrl+'" alt="'+item.title+'" class="list-img">\
                                        <p>'+item.title+'</p>\
                                    </a>\
                                </li>';
                    })
                    $('[data-role="list1"]').html(tpl);
                } else {
                    iosOverlay({
                        text: res.msg,
                        duration: 1000
                    });
                }
            },
            error: function(e) {
            }
        })
    },
    getRecomData2: function() {
        $.ajax({
            url: window.domain + window.requestUrl.getIndexRecomUrl,
            type: 'get',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            data: {
                platId: 2,
                pageSize: 4
            },
            success: function(res) {
                if(typeof(res.not_login) != 'undefined') {
                    window.setCookie('go_back_link', window.location.href);
                    window.location.href = './login.html';
                    return;
                }
                if(res.status) {
                    var list = res.data.result.list;
                    var tpl = '';
                    $.each(list, function(index, item) {
                        tpl += '<li>\
                                    <a href="./wanghong-detail.html?id='+item.id+'" target="_blank">\
                                        <img src="'+item.iconUrl+'" alt="'+item.title+'" class="list-img">\
                                        <p>'+item.title+'</p>\
                                        <p>粉丝数：'+item.fansCount+'</p>\
                                    </a>\
                                </li>';
                    })
                    $('[data-role="list2"]').html(tpl);
                } else {
                    iosOverlay({
                        text: res.msg,
                        duration: 1000
                    });
                }
            },
            error: function(e) {
            }
        })
    },
    getRecomData3: function() {
        $.ajax({
            url: window.domain + window.requestUrl.getIndexRecomUrl,
            type: 'get',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            data: {
                platId: 3,
                pageSize: 4
            },
            success: function(res) {
                if(typeof(res.not_login) != 'undefined') {
                    window.setCookie('go_back_link', window.location.href);
                    window.location.href = './login.html';
                    return;
                }
                if(res.status) {
                    var list = res.data.result.list;
                    var tpl = '';
                    $.each(list, function(index, item) {
                        tpl += '<li>\
                                    <a href="./video-detail.html?id='+item.id+'" target="_blank">\
                                        <img src="'+item.iconUrl+'" alt="'+item.title+'" class="list-img">\
                                        <p>'+item.title+'</p>\
                                        <p>粉丝数：'+item.fansCount+'</p>\
                                    </a>\
                                </li>';
                    })
                    $('[data-role="list3"]').html(tpl);
                } else {
                    iosOverlay({
                        text: res.msg,
                        duration: 1000
                    });
                }
            },
            error: function(e) {
            }
        })
    },
    getRecomData4: function() {
        $.ajax({
            url: window.domain + window.requestUrl.getIndexRecomUrl,
            type: 'get',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            data: {
                platId: 1,
                pageSize: 4
            },
            success: function(res) {
                if(typeof(res.not_login) != 'undefined') {
                    window.setCookie('go_back_link', window.location.href);
                    window.location.href = './login.html';
                    return;
                }
                if(res.status) {
                    var list = res.data.result.list;
                    var tpl = '';
                    $.each(list, function(index, item) {
                        tpl += '<li>\
                                    <a href="./headline-detail.html?id='+item.id+'" target="_blank">\
                                        <img src="'+item.iconUrl+'" alt="'+item.title+'" class="list-img">\
                                        <p>'+item.title+'</p>\
                                        <p>粉丝数：'+item.fansCount+'</p>\
                                    </a>\
                                </li>';
                    })
                    $('[data-role="list4"]').html(tpl);
                } else {
                    iosOverlay({
                        text: res.msg,
                        duration: 1000
                    });
                }
            },
            error: function(e) {
            }
        })
    },
    init: function() {
        this.swiper();
        this.getRecomData1();
        this.getRecomData2();
        this.getRecomData3();
        this.getRecomData4();
    }
}

main.init();
